home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!longbarn.demon.co.uk
- From: Peter Jones <pete@longbarn.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Algorithm - intersection of lines!
- Date: Sat, 20 Jan 1996 15:13:52 GMT
- Organization: None
- Message-ID: <83080835wnr@longbarn.demon.co.uk>
- References: <4dp94nINN822@keats.ugrad.cs.ubc.ca> <4bebi9$eik@news.infi.net> <e3f_9601030228@tor250.org> <4crl7v$bju@news.microsoft.com>
- Reply-To: pete@longbarn.demon.co.uk
- X-NNTP-Posting-Host: longbarn.demon.co.uk
- X-Broken-Date: Saturday, Jan 20, 1996 15.13.52
- X-Newsreader: Newswin Alpha 0.7
- X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!longbarn.demon.co.uk
-
-
- The best way I can think of to approach this problem is to think of the
- lines as vectors, i.e. ai+bj+ck. This way it doesn't matter whether
- it's 3d or 2d (I'll asume 3d).
-
- The equation of a line would be:
-
- r=p+hd
-
- where r=any point on the line
- p=a point known to be on the line
- d=a direction vector describing the line
- h=a number, vary this to get different values for r
-
- If a line , (1), passes thoug a and b, its equation would be:
-
- r(1)=a+h(b-a)
-
- And if the other, (2) line passes though m and n, its equation is:
-
- r(2)=m+g(n-m)
-
- For lines in 3d, there are 3 possibilities:
- they are parallel, ie do not cross
- they are not parallel and do not cross, ie they are skew
- they are not parallel and they do cross.
-
- For the first case, we can see if the lines are parallel by using the
- cross product. If the values for all of the direction vectors comes to
- 0, then they're parallel, i.e. for ai+bj+ck a=b=c=0. If the lines are
- found to be parallel, then they will never cross and you can give up.
-
- OR
-
- The ratios of the direction vectors can be compared, and if they're the same,
- the lines are parallel. For example,
- r(1)=i+j+k+h(3i-2j+4k)
- r(2)=2i-j+3k+g(-6i+4j-8k)
-
- ratio of r(1)=3:-2:4
- ratio of r(2)=-6:4:-8=3:-2:4
-
- Therefore the lines are parallel.
-
- Next, having found the lines not to be parallel, you find out where they
- cross. This happens when r(1)=r(2):
-
- a+h(b-a)=m+g(n-m)
-
- This may seem complicated, but because it's in vectors, we just see where
- the separate components of i, j, and k are equal, which gives us three
- simultaneous equations. You can solve these however you like, by using
- matrices would be one way. From these equations, we find a value of h and
- g, which can be used for one of the equations to find the point in question.
-
- If no solutions can be found, then the lines are skew.
-
- In summary, the steps are
- 1 : Form vector equations of the two lines.
- 2: See if the lines are parallel. If not, continue.
- 3: See if the 3 simultaneous equations formed can be
- solved.
-
- If anyone can see a problem with this solution, please tell me, because
- I worked it out as part of my A-Level revision, and don't want to walk
- into the exam thinking that this is what I want to do.
-
- /-------------------------------------------------------------------------\
- | Peter Jones pete@longbarn.demon.co.uk |
- \-------------------------------------------------------------------------/
-
-